﻿<ResourceDictionary
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:effects="clr-namespace:Noc.Pomodoro.Shaders;assembly=Pomodoro.Shaders"
  xmlns:lookup="clr-namespace:Noc.Pomodoro.ViewModels.Lookup">

  <ResourceDictionary.MergedDictionaries>
    <ResourceDictionary Source="ShinyRed.xaml" />
  </ResourceDictionary.MergedDictionaries>

  <!-- TextBlocks -->
  <Style x:Key="DigitalClockText" TargetType="TextBlock">
    <Setter Property="FontFamily" Value="Bookman Old Style" />
    <Setter Property="FontSize" Value="20" />
  </Style>

  <!-- Brushes -->

  <!-- Buttons -->

  <Style x:Key="TogglePopupButton" TargetType="{x:Type ToggleButton}">
    <Style.Triggers>
      <Trigger Property="IsEnabled" Value="False">
        <Setter Property="Foreground" Value="{DynamicResource DisabledForegroundBrush}"/>
      </Trigger>
    </Style.Triggers>
    <Setter Property="FocusVisualStyle" Value="{StaticResource ButtonFocusVisual}" />
    <Setter Property="Background" Value="{DynamicResource SelectedBackgroundBrush}" />
    <Setter Property="BorderBrush" Value="{DynamicResource NormalBrush}" />
    <Setter Property="BorderThickness" Value="2,2,2,2" />
    <Setter Property="Foreground" Value="{DynamicResource TextBrush}"/>
    <Setter Property="HorizontalContentAlignment" Value="Center" />
    <Setter Property="VerticalContentAlignment" Value="Center" />
    <Setter Property="Padding" Value="1" />
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type ToggleButton}">
          <ControlTemplate.Resources>
            <Storyboard x:Key="HoverOn">
              <DoubleAnimationUsingKeyFrames Storyboard.TargetName="BackgroundAnimation" Storyboard.TargetProperty="Opacity">
                <SplineDoubleKeyFrame KeyTime="00:00:00.1000000" Value="1"/>
              </DoubleAnimationUsingKeyFrames>
            </Storyboard>
            <Storyboard x:Key="HoverOff">
              <DoubleAnimationUsingKeyFrames Storyboard.TargetName="BackgroundAnimation" Storyboard.TargetProperty="Opacity">
                <SplineDoubleKeyFrame KeyTime="00:00:00.4000000" Value="0"/>
              </DoubleAnimationUsingKeyFrames>
            </Storyboard>
          </ControlTemplate.Resources>
          <Grid>

            <Border x:Name="Background" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="4,4,4,4" Opacity="0.9"/>
            <Border x:Name="CheckedBorder" Opacity="1" Background="{StaticResource NormalBrush}" BorderBrush="{DynamicResource NormalBrush}" BorderThickness="2,2,2,2" CornerRadius="4"/>
            <Border x:Name="BackgroundAnimation" Opacity="0" Background="{StaticResource HoverBrush}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="4"/>
            <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" RecognizesAccessKey="True" />
          </Grid>

          <ControlTemplate.Triggers>
            <Trigger Property="IsPressed" Value="True">

            </Trigger>
            <Trigger Property="IsMouseOver" Value="true">
              <Trigger.ExitActions>
                <BeginStoryboard Storyboard="{StaticResource HoverOff}" x:Name="HoverOff_BeginStoryboard"/>
              </Trigger.ExitActions>
              <Trigger.EnterActions>

                <BeginStoryboard Storyboard="{StaticResource HoverOn}" x:Name="HoverOn_BeginStoryboard"/>

              </Trigger.EnterActions>
            </Trigger>
            <Trigger Property="IsKeyboardFocused" Value="true" />
            <Trigger Property="IsEnabled" Value="false">
              <Setter Property="Background" TargetName="Background" Value="{DynamicResource DisabledBackgroundBrush}"/>
              <Setter Property="BorderBrush" TargetName="Background" Value="{DynamicResource DisabledBorderBrush}"/>
            </Trigger>
          </ControlTemplate.Triggers>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>

  <Style x:Key="ToolbarButton" TargetType="{x:Type Button}">
    <Setter Property="Height" Value="20" />
    <Setter Property="Width" Value="20" />

    <Setter Property="Padding" Value="1"/>
    <Setter Property="Margin" Value="0" />
    <Setter Property="Background" Value="Transparent" />
    <Setter Property="BorderBrush" Value="Transparent" />

    <Setter Property="Effect">
      <Setter.Value>
        <effects:GrayscaleEffect SaturationFactor="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=Button}, Path=(effects:GrayscaleEffect.SaturationFactor)}" />
      </Setter.Value>
    </Setter>

    <Setter Property="effects:GrayscaleEffect.SaturationFactor" Value="1" />
    <Setter Property="Opacity" Value="1" />

    <Style.Triggers>
      <Trigger Property="IsMouseOver" Value="True">
        <Setter Property="Background" Value="{DynamicResource NormalBrush}" />
      </Trigger>
      <Trigger Property="IsEnabled" Value="False">
        <Setter Property="effects:GrayscaleEffect.SaturationFactor" Value="0" />
        <Setter Property="Opacity" Value="0.35" />
      </Trigger>
    </Style.Triggers>
  </Style>

  <!-- Images -->

  <Style x:Key="BaseIconStyle" TargetType="{x:Type Image}">
    <Setter Property="Height" Value="16" />
    <Setter Property="Margin" Value="1,2,0,2" />
  </Style>

  <Style x:Key="TaskIconStyle" TargetType="{x:Type Image}" BasedOn="{StaticResource BaseIconStyle}">
    <Setter Property="Source" Value="{x:Null}" />
    <Style.Triggers>

      <DataTrigger Binding="{Binding TaskType}">
        <DataTrigger.Value>
          <lookup:TaskState>ToDoToday</lookup:TaskState>
        </DataTrigger.Value>
        <Setter Property="Source" Value="/Pomodoro;component/Resources/Type-Planned.png" />
      </DataTrigger>

      <DataTrigger Binding="{Binding TaskType}">
        <DataTrigger.Value>
          <lookup:TaskState>UrgentUnplanned</lookup:TaskState>
        </DataTrigger.Value>
        <Setter Property="Source" Value="/Pomodoro;component/Resources/Type-Urgent.png" />
      </DataTrigger>

      <DataTrigger Binding="{Binding TaskType}">
        <DataTrigger.Value>
          <lookup:TaskState>Activity</lookup:TaskState>
        </DataTrigger.Value>
        <Setter Property="Source" Value="/Pomodoro;component/Resources/Type-Activity.png" />
      </DataTrigger>

      <DataTrigger Binding="{Binding TaskType}">
        <DataTrigger.Value>
          <lookup:TaskState>Completed</lookup:TaskState>
        </DataTrigger.Value>
        <Setter Property="Source" Value="/Pomodoro;component/Resources/Type-Completed.png" />
      </DataTrigger>

      <DataTrigger Binding="{Binding TaskType}">
        <DataTrigger.Value>
          <lookup:TaskState>Canceled</lookup:TaskState>
        </DataTrigger.Value>
        <Setter Property="Source" Value="/Pomodoro;component/Resources/Type-Canceled.png" />
      </DataTrigger>

    </Style.Triggers>
  </Style>

  <Style x:Key="EventIconStyle" TargetType="{x:Type Image}" BasedOn="{StaticResource BaseIconStyle}">
    <Setter Property="Source" Value="{x:Null}" />
    <Style.Triggers>

      <!-- PomodoroEventType.InternalInterrupt -->
      <DataTrigger Binding="{Binding EventType}">
        <DataTrigger.Value>
          <lookup:PomodoroEventType>InternalInterrupt</lookup:PomodoroEventType>
        </DataTrigger.Value>
        <Setter Property="Source" Value="/Pomodoro;component/Resources/Event-InternalInterrupt.png" />
      </DataTrigger>

      <!-- PomodoroEventType.ExternalInterrupt -->
      <DataTrigger Binding="{Binding EventType}">
        <DataTrigger.Value>
          <lookup:PomodoroEventType>ExternalInterrupt</lookup:PomodoroEventType>
        </DataTrigger.Value>
        <Setter Property="Source" Value="/Pomodoro;component/Resources/Event-ExternalInterrupt.png" />
      </DataTrigger>

    </Style.Triggers>
  </Style>

  <Style x:Key="AddPomodoroIconStyle" TargetType="{x:Type Image}" BasedOn="{StaticResource BaseIconStyle}">
    <Setter Property="Source" Value="/Pomodoro;component/Resources/Action-AddEstimate.png" />
    <Setter Property="Opacity" Value="0.15" />
    <Setter Property="Visibility" Value="Visible" />
    <Style.Triggers>
      <Trigger Property="IsMouseOver" Value="True">
        <Setter Property="Opacity" Value="1.0" />
      </Trigger>
      <DataTrigger Binding="{Binding Title}" Value="{x:Null}">
        <Setter Property="Visibility" Value="Collapsed" />
      </DataTrigger>
      <DataTrigger Binding="{Binding TaskType}">
        <DataTrigger.Value>
          <lookup:TaskState>Completed</lookup:TaskState>
        </DataTrigger.Value>
        <Setter Property="Visibility" Value="Collapsed" />
      </DataTrigger>
      <DataTrigger Binding="{Binding TaskType}">
        <DataTrigger.Value>
          <lookup:TaskState>Canceled</lookup:TaskState>
        </DataTrigger.Value>
        <Setter Property="Visibility" Value="Collapsed" />
      </DataTrigger>
    </Style.Triggers>
  </Style>

  <Style x:Key="PomodoroIconStyle" TargetType="{x:Type Image}" BasedOn="{StaticResource BaseIconStyle}">
    <Setter Property="Source" Value="{x:Null}" />
    <Style.Triggers>

      <!-- Planned + PomodoroState.NotStarted -->
      <MultiDataTrigger>
        <MultiDataTrigger.Conditions>
          <Condition Binding="{Binding IsPlanned}" Value="True"></Condition>
          <Condition Binding="{Binding State}">
            <Condition.Value>
              <lookup:PomodoroState>NotStarted</lookup:PomodoroState>
            </Condition.Value>
          </Condition>
        </MultiDataTrigger.Conditions>
        <Setter Property="Source" Value="/Pomodoro;component/Resources/State-Planned.png" />
      </MultiDataTrigger>

      <!-- Planned + PomodoroState.NotStarted + MouseOver -->
      <MultiDataTrigger>
        <MultiDataTrigger.Conditions>
          <Condition Binding="{Binding IsPlanned}" Value="True"></Condition>
          <Condition Binding="{Binding RelativeSource={RelativeSource Self}, Path=IsMouseOver}" Value="True" />
          <Condition Binding="{Binding State}">
            <Condition.Value>
              <lookup:PomodoroState>NotStarted</lookup:PomodoroState>
            </Condition.Value>
          </Condition>
        </MultiDataTrigger.Conditions>
        <Setter Property="Source" Value="/Pomodoro;component/Resources/Action-DeleteEstimate.png" />
      </MultiDataTrigger>

      <!-- Unplanned + PomodoroState.NotStarted -->
      <MultiDataTrigger>
        <MultiDataTrigger.Conditions>
          <Condition Binding="{Binding IsPlanned}" Value="False"></Condition>
          <Condition Binding="{Binding State}">
            <Condition.Value>
              <lookup:PomodoroState>NotStarted</lookup:PomodoroState>
            </Condition.Value>
          </Condition>
        </MultiDataTrigger.Conditions>
        <Setter Property="Source" Value="/Pomodoro;component/Resources/State-Unplanned.png" />
      </MultiDataTrigger>

      <!-- Planned + PomodoroState.Running -->
      <MultiDataTrigger>
        <MultiDataTrigger.Conditions>
          <Condition Binding="{Binding IsPlanned}" Value="True"></Condition>
          <Condition Binding="{Binding State}">
            <Condition.Value>
              <lookup:PomodoroState>Running</lookup:PomodoroState>
            </Condition.Value>
          </Condition>
        </MultiDataTrigger.Conditions>
        <Setter Property="Source" Value="/Pomodoro;component/Resources/State-RunningPlanned.png" />
      </MultiDataTrigger>

      <!-- Unplanned + PomodoroState.Running -->
      <MultiDataTrigger>
        <MultiDataTrigger.Conditions>
          <Condition Binding="{Binding IsPlanned}" Value="False"></Condition>
          <Condition Binding="{Binding State}">
            <Condition.Value>
              <lookup:PomodoroState>Running</lookup:PomodoroState>
            </Condition.Value>
          </Condition>
        </MultiDataTrigger.Conditions>
        <Setter Property="Source" Value="/Pomodoro;component/Resources/State-RunningUnplanned.png" />
      </MultiDataTrigger>

      <!-- Planned + PomodoroState.Voided -->
      <MultiDataTrigger>
        <MultiDataTrigger.Conditions>
          <Condition Binding="{Binding IsPlanned}" Value="True"></Condition>
          <Condition Binding="{Binding State}">
            <Condition.Value>
              <lookup:PomodoroState>Voided</lookup:PomodoroState>
            </Condition.Value>
          </Condition>
        </MultiDataTrigger.Conditions>
        <Setter Property="Source" Value="/Pomodoro;component/Resources/State-VoidedPlanned.png" />
      </MultiDataTrigger>

      <!-- Unplanned + PomodoroState.Voided -->
      <MultiDataTrigger>
        <MultiDataTrigger.Conditions>
          <Condition Binding="{Binding IsPlanned}" Value="False"></Condition>
          <Condition Binding="{Binding State}">
            <Condition.Value>
              <lookup:PomodoroState>Voided</lookup:PomodoroState>
            </Condition.Value>
          </Condition>
        </MultiDataTrigger.Conditions>
        <Setter Property="Source" Value="/Pomodoro;component/Resources/State-VoidedUnplanned.png" />
      </MultiDataTrigger>

      <!-- Planned + PomodoroState.Completed -->
      <MultiDataTrigger>
        <MultiDataTrigger.Conditions>
          <Condition Binding="{Binding IsPlanned}" Value="True"></Condition>
          <Condition Binding="{Binding State}">
            <Condition.Value>
              <lookup:PomodoroState>Completed</lookup:PomodoroState>
            </Condition.Value>
          </Condition>
        </MultiDataTrigger.Conditions>
        <Setter Property="Source" Value="/Pomodoro;component/Resources/State-CompletedPlanned.png" />
      </MultiDataTrigger>

      <!-- Unplanned + PomodoroState.Completed -->
      <MultiDataTrigger>
        <MultiDataTrigger.Conditions>
          <Condition Binding="{Binding IsPlanned}" Value="False"></Condition>
          <Condition Binding="{Binding State}">
            <Condition.Value>
              <lookup:PomodoroState>Completed</lookup:PomodoroState>
            </Condition.Value>
          </Condition>
        </MultiDataTrigger.Conditions>
        <Setter Property="Source" Value="/Pomodoro;component/Resources/State-CompletedUnplanned.png" />
      </MultiDataTrigger>

    </Style.Triggers>
  </Style>

  <!-- DataGrids -->

  <Style TargetType="DataGrid">

    <!-- Make the border and grid lines a little less imposing -->
    <Setter Property="BorderBrush" Value="#DDDDDD" />
    <Setter Property="HorizontalGridLinesBrush" Value="#DDDDDD" />
    <Setter Property="VerticalGridLinesBrush" Value="#DDDDDD" />

    <Setter Property="RowStyle">
      <Setter.Value>
        <Style TargetType="DataGridRow">
          <!--<Setter Property="Background" Value="{DynamicResource NormalBrush}" />-->
          <Style.Triggers>
            <!-- Highlight a grid row as the mouse passes over -->
            <Trigger Property="IsMouseOver" Value="True">
              <Setter Property="Background" Value="{DynamicResource MouseOverBrush}" />
            </Trigger>
          </Style.Triggers>
        </Style>
      </Setter.Value>
    </Setter>

    <Setter Property="CellStyle">
      <Setter.Value>
        <Style TargetType="DataGridCell">
          <Style.Triggers>
            <!-- Highlight closed/canceled tasks -->
            <DataTrigger Binding="{Binding TaskType}">
              <DataTrigger.Value>
                <lookup:TaskState>Completed</lookup:TaskState>
              </DataTrigger.Value>
              <Setter Property="Foreground" Value="Green" />
              <Setter Property="FontStyle" Value="Italic" />
            </DataTrigger>
            <DataTrigger Binding="{Binding TaskType}">
              <DataTrigger.Value>
                <lookup:TaskState>Canceled</lookup:TaskState>
              </DataTrigger.Value>
              <Setter Property="Foreground" Value="DarkGray" />
              <Setter Property="FontStyle" Value="Italic" />
            </DataTrigger>

            <!-- Highlight selected rows -->
            <Trigger Property="IsSelected" Value="True">
              <Setter Property="Background" Value="{StaticResource SelectedBackgroundBrush}" />
              <Setter Property="BorderBrush" Value="{StaticResource PressedBorderBrush}" />
              <Setter Property="Foreground" Value="{StaticResource LightBrush}" />
            </Trigger>
          </Style.Triggers>

          <!-- Add some padding around the contents of a cell -->
          <Setter Property="Template">
            <Setter.Value>
              <ControlTemplate TargetType="DataGridCell">
                <Border Padding="{TemplateBinding Padding}" Background="{TemplateBinding Background}">
                  <ContentPresenter />
                </Border>
              </ControlTemplate>
            </Setter.Value>
          </Setter>
        </Style>
      </Setter.Value>
    </Setter>
  </Style>

  <Style TargetType="{x:Type TextBlock}" x:Key="TaskTextStyle">

    <Style.Triggers>
      <!-- Highlight closed/canceled tasks -->
      <DataTrigger Binding="{Binding TaskType}">
        <DataTrigger.Value>
          <lookup:TaskState>Completed</lookup:TaskState>
        </DataTrigger.Value>
        <Setter Property="TextDecorations" Value="Strikethrough" />
      </DataTrigger>
      <DataTrigger Binding="{Binding TaskType}">
        <DataTrigger.Value>
          <lookup:TaskState>Canceled</lookup:TaskState>
        </DataTrigger.Value>
        <Setter Property="TextDecorations" Value="Strikethrough" />
      </DataTrigger>
    </Style.Triggers>

  </Style>

</ResourceDictionary>